package com.finace.money.presenter;

import com.finace.money.common.Constant;
import com.finace.money.common.util.ACache;
import com.finace.money.common.util.UIUtil;
import com.finace.money.data.bean.StatusListBean;
import com.finace.money.net.socket.PushReceiver;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by zhangpeng on 2018/1/16.
 */

public class MyChoosePresenter {

    public MyChoosePresenter() {
    }

    public void setChoose(List<StatusListBean> statusLists, StatusListBean statusListBean) {

        ACache aCache = ACache.get(UIUtil.getContext());
        statusListBean.setCheck(!statusListBean.getCheck());
        aCache.put(PushReceiver.ACTION_LIST, (Serializable) statusLists);
        List<StatusListBean> chooseLists = new ArrayList<>();
        for (StatusListBean bean : statusLists) {
            if (bean.getCheck()) {
                chooseLists.add(bean);
            }
        }
        aCache.put(Constant.CHOOSE_ALL, (Serializable) chooseLists);
    }

    public void removeChoose(List<StatusListBean> data, StatusListBean remove) {
        ACache aCache = ACache.get(UIUtil.getContext());
        if (data.contains(remove)) {
            data.remove(remove);
        }
        aCache.put(Constant.CHOOSE_ALL, (Serializable) data);
        List<StatusListBean> allLists = (List<StatusListBean>) aCache.getAsObject(PushReceiver.ACTION_LIST);
        for (StatusListBean bean : allLists) {
            if (bean.getM_Body().getM_ProductID().equals(remove.getM_Body().getM_ProductID())) {
                bean.setCheck(false);
                break;
            }
        }
        aCache.put(PushReceiver.ACTION_LIST, (Serializable) allLists);
    }
}
